﻿using DynamicWebProxy.EventArgs;
using DynamicWebProxy.Resolvers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DynamicWebProxy
{
    public class ProxyFactory : ProxyGenerator
    {
        public override event EventHandler<GenerateLoadSucceedEventArgs>? OnGenerateLoadSucceed;

        public override event EventHandler<GenerateLoadFailedEventArgs>? OnGenerateLoadFailed;

        public override async Task GenerateProxyItems()
        {
            Source = "代理池";

            ProxyGenerator xiaohuan = new XiaohuanGenerator() { MaxValidTimes = 2 };
            xiaohuan.OnGenerateLoadSucceed += OnGenerateLoadSucceed;
            xiaohuan.OnGenerateLoadFailed += OnGenerateLoadFailed;
            await xiaohuan.GenerateProxyItems();

            ProxyGenerator kuai = new KuaiGenerator() { MaxValidTimes = 2 };
            kuai.OnGenerateLoadSucceed += OnGenerateLoadSucceed;
            kuai.OnGenerateLoadFailed += OnGenerateLoadFailed;
            await kuai.GenerateProxyItems();

            ProxyGenerator mifeng = new MifengGenerator() { MaxValidTimes = 2 };
            mifeng.OnGenerateLoadSucceed += OnGenerateLoadSucceed;
            mifeng.OnGenerateLoadFailed += OnGenerateLoadFailed;
            await mifeng.GenerateProxyItems();

            ProxyItems.AddRange(xiaohuan.ProxyItems);
            ProxyItems.AddRange(kuai.ProxyItems);
            ProxyItems.AddRange(mifeng.ProxyItems);

#if DEBUG
            await TestAll();
#endif
        }
    }
}